//
//  ERHomeTableViewCell.m
//  ExchangeRate
//
//  Created by 方义强 on 15/11/7.
//  Copyright © 2015年 方义强. All rights reserved.
//

#import "ERHomeTableViewCell.h"
#define kCellHeight (kSCREENHEIGHT * 2 / 3 - 70) / 4
#define kImageViewX 25
#define kImageViewY 25
#define kImageViewWidth 40
#define kImageViewHeight 40

@implementation ERHomeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSCREENWIDTH, kCellHeight)];
        _scrollView.contentSize = CGSizeMake(kSCREENWIDTH * 2, kCellHeight);
        _scrollView.contentOffset = CGPointMake(kSCREENWIDTH, 0);
        _scrollView.pagingEnabled = YES;
        _scrollView.userInteractionEnabled = YES;
        _scrollView.showsHorizontalScrollIndicator = NO;
        [self.contentView addSubview:_scrollView];
        
        UIView *firstView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSCREENWIDTH, kCellHeight)];
        firstView.backgroundColor = [UIColor colorWithRed:0.032 green:0.777 blue:0.929 alpha:1.000];
        [_scrollView addSubview:firstView];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(kSCREENWIDTH - 180, kCellHeight / 2 - 15, 160, 30)];
        label.font = [UIFont systemFontOfSize:20];
        label.textAlignment = NSTextAlignmentRight;
        label.textColor = [UIColor whiteColor];
        label.text = NSLocalizedString(@"切换货币", nil);
        [firstView addSubview:label];
        
        _nationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kSCREENWIDTH + kImageViewX, kCellHeight / 2 - 20, kImageViewWidth, kImageViewHeight)];
        _nationImageView.backgroundColor = [UIColor grayColor];
        [_scrollView addSubview:_nationImageView];
        
        CGFloat nationLabelWidth = 40;
        _nationLabel = [[UILabel alloc] initWithFrame:CGRectMake(kSCREENWIDTH + kImageViewX + kImageViewWidth + 15, kCellHeight / 2 - 10, nationLabelWidth, 20)];
        _nationLabel.font = [UIFont systemFontOfSize:18];
        _nationLabel.textColor = [UIColor grayColor];
        _nationLabel.text = @"CNY";
        [_scrollView addSubview:_nationLabel];
        
        _locationView = [[UIImageView alloc] initWithFrame:CGRectMake(kSCREENWIDTH + kImageViewX + kImageViewWidth + 15 + nationLabelWidth, kCellHeight / 2 - 10, 20, 20)];
//        _locationView.backgroundColor = [UIColor grayColor];
        [_scrollView addSubview:_locationView];
        
        _caculatorTF = [[UITextField alloc] initWithFrame:CGRectMake(kSCREENWIDTH + kSCREENWIDTH / 2, kCellHeight / 2 - 30, kSCREENWIDTH / 2 - 20, 15)];
        _caculatorTF.textColor = [UIColor grayColor];
        _caculatorTF.userInteractionEnabled = NO;
        _caculatorTF.inputView = [[UIView alloc] initWithFrame:CGRectZero];
        _caculatorTF.textAlignment = NSTextAlignmentRight;
        _caculatorTF.font = [UIFont systemFontOfSize:12];
        [_scrollView addSubview:_caculatorTF];
        
        CGFloat resultX = kImageViewX + kImageViewWidth + 15 + nationLabelWidth + 20;
        _resultTF = [[UITextField alloc] initWithFrame:CGRectMake(kSCREENWIDTH + resultX, kCellHeight / 2 - 15, kSCREENWIDTH - resultX - 20, 30)];
        _resultTF.textColor = [UIColor blackColor];
        _resultTF.userInteractionEnabled = NO;
        _resultTF.inputView = [[UIView alloc] initWithFrame:CGRectZero];
        _resultTF.textAlignment = NSTextAlignmentRight;
        
        _resultTF.font = [UIFont fontWithName:@"STHeitiTC-Light" size:30];
        _resultTF.placeholder = @"100";
        [_scrollView addSubview:_resultTF];
        
        _nationNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(kSCREENWIDTH + kSCREENWIDTH / 2, kCellHeight / 2 + 15, kSCREENWIDTH / 2 - 20, 13)];
        _nationNameLabel.textColor = [UIColor lightGrayColor];
        _nationNameLabel.textAlignment = NSTextAlignmentRight;
        _nationNameLabel.font = [UIFont systemFontOfSize:11];
        _nationNameLabel.text = @"人民币";
        [_scrollView addSubview:_nationNameLabel];
        
    }
    return self;
}

- (void)setConfigureModel:(ERResourceModel *)configureModel
{
    _nationImageView.image = [UIImage imageNamed:configureModel.fields.name];
    _nationLabel.text = configureModel.fields.name;
    _nationNameLabel.text = configureModel.nameStr;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
